/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package converters;

import com.mycompany.psc.ejb.ReportableItemsManager;
import com.mycompany.psc.entities.Carpenter;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author A7med
 */
@FacesConverter(forClass = Carpenter.class,value = "carpenterConverter")
public class CarpenterConverter implements Converter{
     @EJB
    ReportableItemsManager rm;
      @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return rm.getResourceByName("Carpenter.findByTitleAndProject","title",value);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
       if(value instanceof Carpenter){
            Carpenter u=(Carpenter)value;
    
        return u.getTitle();
        }else{
            return "no value";
        }
    }
}
